import { Form } from 'multiparty';
import resultEnum from '../utils/resultEnum.js';
import Mocks from '../utils/mock.js';
const Mock = new Mocks();
/* 查询地址信息 */
export function selectTemplateInfo (ctx, next) {
  try {
    const params = {
      ...ctx.query
    };
    console.log(params);
    /* 模拟查询数据库，处理后返回 */
    /* 返回对象 */

    ctx.success(resultEnum.GET_SUCCESS.code, resultEnum.GET_SUCCESS.msg, Mock.getTemplateList())
  } catch (error) {
    ctx.error(resultEnum.GET_ERROR.code, resultEnum.GET_ERROR.msg)
  }
}

/* 查询地址信息通过id */
export function selectTemplateInfoById (ctx, next) {
  const params = {
    ...ctx.params
  };
  console.log(params);
  ctx.success(resultEnum.GET_SUCCESS.code, resultEnum.GET_SUCCESS.msg, Mock.getTemplateById())
}

/* 新增地址信息 */
export function insertTemplate (ctx, next) {
  const params = {
    ...ctx.request.body
  };

  var form = new Form({
    uploadDir: 'temp'
  });
  console.log(ctx.req);
  form.parse(ctx.req);
  form.on('file', () => {
    console.log('上传成功');
  })
  ctx.success(resultEnum.SAVE_SUCCESS.code, resultEnum.SAVE_SUCCESS.msg)
}

/* 更新地址信息 */
export function updateTemplate (ctx, next) {
  const params = {
    ...ctx.request.body,
    ...ctx.params
  };
  console.log(params);
  ctx.success(resultEnum.UPDATE_SUCCESS.code, resultEnum.UPDATE_SUCCESS.msg)
}

/* 删除地址信息 */
export function deleteTemplate (ctx, next) {
  const params = {
    ...ctx.params
  };
  console.log(params);
  ctx.success(resultEnum.DELETE_SUCCESS.code, resultEnum.DELETE_SUCCESS.msg)
}

// export default {
//   selectTemplateInfo,
//   selectTemplateInfoById,
//   insertTemplate,
//   updateTemplate,
//   deleteTemplate
// }